package com.ldy.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ldy.core.entity.BaseSetting;
import com.ldy.core.mapper.BaseSettingMapper;
import com.ldy.core.service.BaseSettingService;

@Service
public class BaseSettingServiceImpl extends ServiceImpl<BaseSettingMapper, BaseSetting>  implements BaseSettingService{

	@Autowired
	private BaseSettingMapper mapper;
	
	@Override
	public String get(String code) {
		QueryWrapper<BaseSetting> query = new QueryWrapper<>();
		query.eq("code", code);
		BaseSetting selectOne = mapper.selectOne(query);
		if (null == selectOne) {
			return "";
		}
		return selectOne.getValue();
	}

	@Override
	public void save(String code, String value) {
		QueryWrapper<BaseSetting> query = new QueryWrapper<>();
		query.eq("code", code);
		BaseSetting selectOne = mapper.selectOne(query);
		if (null == selectOne) {
			BaseSetting setting = new BaseSetting();
			setting.setCode(code);
			setting.setValue(value);
			mapper.insert(setting);
		} else {
			selectOne.setValue(value);
			mapper.updateById(selectOne);
		}
	}

	@Override
	public List<BaseSetting> getConfig(String[] code) {
		QueryWrapper<BaseSetting> query = new QueryWrapper<>();
		query.in("code", code);
		return mapper.selectList(query);
	}

}
